package com.example.rocktmqsample.produce;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionState;
import org.springframework.messaging.Message;


@Slf4j
@RocketMQTransactionListener
public class MyTransactionListener implements RocketMQLocalTransactionListener {
    @Override
    public RocketMQLocalTransactionState executeLocalTransaction(Message msg, Object arg) {
        // 执行本地事务，可以是数据库操作、业务处理等
        // 返回 COMMIT、ROLLBACK 或 UNKNOWN
        return RocketMQLocalTransactionState.COMMIT;
    }

    @Override
    public RocketMQLocalTransactionState checkLocalTransaction(Message msg) {
        // 根据消息状态回查本地事务状态，返回 COMMIT、ROLLBACK 或 UNKNOWN
        return RocketMQLocalTransactionState.ROLLBACK;
    }
}
